{extend name='public/layout' /}
{block name='content'}
<style>
    .main{padding:10px;background-color: #fff;}
    .am-form .am-form-group input{padding:8px 8px 8px 28px;}
</style>
<div class="main ">
    <div class="ylj-box ylj-padding-t-b ylj-margin-b">
        <form action="{:url('pass')}" method="post" id="myForm" data-uri="{:url('ajaxCheckUser')}" class="am-form ylj-padding-l-r" >
            <div class="am-form-group am-form-icon">
                <i class="am-icon-phone"></i>
                <input type="text" name="mobile" id="mobile" class="am-form-field" placeholder="注册时填写的手机号码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-envelope"></i>
                <input type="text" name="email" id="email" class="am-form-field" placeholder="注册时填写的邮箱号码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-image"></i>
                <input type="text" class="am-form-field" name="code" id="code" style="padding-right:140px;" placeholder="验证码">
                <button type="button" onclick="getCode();" id="smsCode" class="am-fr am-btn ylj-btn-color" style="position:absolute;top:0;right:0;">获取验证码</button>
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-lock"></i>
                <input type="password" name="password" id="password" class="am-form-field" placeholder="密码">
            </div>
            <div class="am-form-group am-form-icon">
                <i class="am-icon-lock"></i>
                <input type="password" name="repassword" id="password2" class="am-form-field" placeholder="确认密码">
            </div>

            <div class="am-form-group">
                <button type="button" id="ylj-sub-btn" onclick="$('#myForm').submit();" class="am-btn ylj-btn-color am-btn-block am-round">重置密码</button>
            </div>
        </form>
    </div>

</div>
<script src="__PUBLIC__/js/plugins/layervalide.js"></script>
<script src="__PUBLIC__/js/plugins/jquery.ajax.form.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    $(function(){
        $.formValidator.initConfig({formid:"myForm",autotip:true});
        $("#mobile").formValidator({onshow:'',onfocus:'请填写手机号码'}).regexValidator({regexp:"mobile",datatype:"enum",onerror:"请填写注册时的手机号码"}).ajaxValidator({
            type : "get",
            url : $('#myForm').data('uri'),
            datatype : "json",
            async:'false',
            success : function(result){
                if(result.status == 1){
                    return false;
                }else{
                    return true;
                }
            },
            onerror : '该手机号码不存在',
            onwait : '查询中,请稍候...'
        });
        $("#email").formValidator({onshow:'',onfocus:'请填写邮箱号码'}).regexValidator({regexp:"email",datatype:"enum",onerror:"请填写注册时的邮箱号码"}).ajaxValidator({
            type : "get",
            url : $('#myForm').data('uri'),
            datatype : "json",
            async:'false',
            success : function(result){
                if(result.status == 1){
                    return false;
                }else{
                    return true;
                }
            },
            onerror : '该邮箱号码不存在',
            onwait : '查询中,请稍候...'
        });
        $("#code").formValidator({onshow:'',onfocus:'请填写验证码'}).inputValidator({min:6,max:6,onerror:'验证码由6个字符组成'});
        $("#password").formValidator({onshow:'',onfocus:'请填写密码'}).inputValidator({min:6,onerror:'密码至少由6个字符组成'});
        $("#repassword").formValidator({onshow:"",onfocus:"请再次填写密码"}).compareValidator({desid:"password",operateor:"=",onerror:"输入两次密码不同。"});
        $('#myForm').ajaxForm({success:complate,dataType:'json'});
        function complate(result){
            if(result.status == 1){
                layer.msg(result.msg,{icon:1});
                setTimeout(function(){window.location.href = result.uri;},2000);
            } else {
                layer.msg(result.msg,{icon:2});
            }
        }
    });
    var time=60,times='';
    function getCode(){
        if(time<60) return false;
        var email = $("#email").val(),mobile=$("#mobile").val();
        $.post("{:url('user.login/getEmailCode')}",{'email':email,'mobile':mobile},function(data){
            if(data.status==1){
                time --;
                layer.msg('验证码发送成功，请注意查收',{icon:1});
                times = setInterval(timer,1000);
            }else{
                layer.msg(data.msg);
            }
        });
    }
    function timer(){
        var code = $("#smsCode");
        if(time == 0){
            time = 61;
            code.text('获取验证码');
            clearInterval(times);

        }else{
            code.text(time+'秒后重新获取');
        }
        time --;
    }
</script>
{/block}